﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace btnet.pages
{
    public partial class delete_report : CommonPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Bug_Util.do_not_cache(Response);

            security = new Security();

            security.check_security(HttpContext.Current, Security.ANY_USER_OK_EXCEPT_GUEST);

            if (security.user.is_admin || security.user.can_edit_reports)
            {
                //
            }
            else
            {
                Response.Write("You are not allowed to use this page.");
                Response.End();
            }

            if (IsPostBack)
            {
                // do delete here
                sql = @"
delete reports where rp_id = $1;
delete dashboard_items where ds_report = $1";
                sql = sql.Replace("$1", row_id.Value);
                DbUtil.execute_nonquery(sql);
                Server.Transfer("reports.aspx");
            }
            else
            {
                titl.Text = Bug_Util.get_setting("AppTitle", "BugTracker.NET") + " - "
                    + "delete report";

                string id = Bug_Util.sanitize_integer(Request["id"]);

                sql = @"select rp_desc from reports where rp_id = $1";
                sql = sql.Replace("$1", id);

                DataRow dr = DbUtil.get_datarow(sql);

                confirm_href.InnerText = "confirm delete of report: "
                        + Convert.ToString(dr["rp_desc"]);

                row_id.Value = id;

            }
        }
    }
}
